﻿(function () {
    if (!Object.create) {
        Object.create = function (obj) {
            function f() { };
            f.prototype = obj;
            return new f();
        }
    }
})();

var Class = {
    create: function (properties) {
        var theClass = function () {
            this.init.apply(this, arguments);
        }
        theClass.prototype = {};
        for (var prop in properties) {
            theClass.prototype[prop] = properties[prop];
        }
        if (!theClass.prototype.init) {
            theClass.prototype.init = function () { }
        }
        return theClass;
    },
    super: function (parent, curent, args) {
        this._super = new parent(args);
        parent.apply(curent, args);
    },
};

Function.prototype.inherit = function (parent) {
    var oldPrototype = this.prototype;
    var parentPrototype = new parent();
    this.prototype = Object.create(parentPrototype);
    //this.prototype._super = parentPrototype; -> this results in an infinite recursion for multiple levels of inheritance
    for (var prop in oldPrototype) {
        this.prototype[prop] = oldPrototype[prop];
    }
};
